// import { getCookie } from './util'
const LOCAL_SIDE_KEY = 'side-bar'
const LOCAL_ACCESS_KEY = 'mobile_access_token'
const LOCAL_REFRESH_KEY = 'mobile_refresh_token'
const LOCAL_USER_KEY = 'user-info'
const IS_LOGIN = 'is_login'
const storageObj: any = window.localStorage

// export function getSidebBar() {
//   // 从storageObj中获取LOCAL_SIDE_KEY对应的值，如果没有则返回'1'
//   return storageObj.getItem(LOCAL_SIDE_KEY) || '1'
// }

// export function setSidebBar(token: string) {
//   storageObj.setItem(LOCAL_SIDE_KEY, token.toString())
// }

// export function removeSidebBar() {
//   storageObj.removeItem(LOCAL_SIDE_KEY)
// }


export const getToken = () => {
  // return getCookie(LOCAL_ACCESS_KEY)
  return storageObj.getItem(LOCAL_ACCESS_KEY)
}

export const setToken = (token: string) => {
  storageObj.setItem(LOCAL_ACCESS_KEY, token)
}

export const removeToken = () => {
  storageObj.removeItem(LOCAL_ACCESS_KEY)
}


export const getRefreshToken = () => {
  // return getCookie(LOCAL_REFRESH_KEY)
  return storageObj.getItem(LOCAL_REFRESH_KEY)
}

export const setRefreshToken = (token: string) => {
  storageObj.setItem(LOCAL_REFRESH_KEY, token)
}

export const removeRefreshToken = () => {
  storageObj.removeItem(LOCAL_REFRESH_KEY)
}

//
// export function getUserInfo() {
//   return storageObj.getItem(LOCAL_USER_KEY)
// }

// export function setUserInfo(token: string[]) {
//   storageObj.setItem(LOCAL_USER_KEY, token)
// }

// export function removeUserInfo() {
//   storageObj.removeItem(LOCAL_USER_KEY)
// }
// 是否登录
export const getIsLogin = () => {
  return storageObj.getItem(IS_LOGIN)
}

export const setIsLogin = (flag: string) => {
  storageObj.setItem(IS_LOGIN, flag)
}

export const removeIsLogin = () => {
  storageObj.removeItem(IS_LOGIN)
}

export const cleanStorage = () => {
  // const keys = document.cookie.match(/[^ =;]+(?==)/g)
  // if (keys) {
  //   for (let i = keys.length; i--; ) {
  //     document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString() + ';max-age=0'
  //   }
  // }
  storageObj.clear()
}
